﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CNPageViewer
{
    /// <summary>
    /// This control shows one page and associated information. It is designed to
    /// be used by the PageFlowControl which hosts one of these for each page it 
    /// shows.
    /// 
    /// This control shows:
    /// - A background color that can be set according to the creation date of
    ///   the page.
    /// - A PageViewerControl to show a thumbnail of the page.
    /// - Some optional title text.
    /// </summary>
    public partial class PageFlowItemControl : UserControl
    {
        #region Public properties

        /// <summary>
        /// Gets the PageViewerControl that show the page thumbnail.
        /// </summary>
        public PageViewerControl PageViewerControl
        {
            get { return ctrlPageViewer; }
        }

        /// <summary>
        /// Sets the Text label.
        /// </summary>
        public string Text
        {
            set { lblText.Text = value; }
        }

        /// <summary>
        /// Gets or sets the Valid flag. Used to help work out which of these control is needed at any one time.
        /// </summary>
        public bool Valid { get; set; }

        #endregion

        #region Public methods

        /// <summary>
        /// Constructor.
        /// </summary>
        public PageFlowItemControl()
        {
            InitializeComponent();
            Valid = true;
        }

        /// <summary>
        /// Cleans up the control when it is no longer needed.
        /// </summary>
        public void close()
        {
            ctrlPageViewer.close();
        }

        #endregion

        #region Private functions

        /// <summary>
        /// Called when the page-viewer control is clicked.
        /// </summary>
        private void ctrlPageViewer_MouseClick(object sender, MouseEventArgs e)
        {
            // We raise our own click event. We first need to translate the
            // mouse position - which is relative to the page-viewer control - 
            // into coordinates relative to this control...
            Point screenPoint = ctrlPageViewer.PointToScreen(e.Location);
            Point clientPoint = PointToClient(screenPoint);
            MouseEventArgs args = new MouseEventArgs(e.Button, e.Clicks, clientPoint.X, clientPoint.Y, e.Delta);
            OnMouseClick(args);
        }

        #endregion

    }
}
